<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link href="${ctx}/static/css/plugins/jsTree/default/style.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row animated fadeInRight">
			<div class="col-sm-3">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>系统字典</h5>
					</div>
					<div>
						<div class="ibox-content profile-content">
							<form id="treeSearch" class="form-inline">
								<div class="form-group ">
									<input type="text" id="searchLable" placeholder="标签名" class="form-control" style="width: 120px">
									<button class="btn btn-outline btn-info" type="submit">
										<i class="fa fa-search"></i>
									</button>
								</div>
							</form>
							<div id="dictTree"></div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-sm-9">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>查询条件</h5>
					</div>
					<input type="hidden" id="parentId" value="-1">
					<div class="ibox-content">
						<form id="queryForm" class="form-inline">
							<div class="form-group">
								<input type="text" name="likeName" id="likeName" placeholder="类型编码或者标签名" class="form-control">
							</div>
							<div class="form-group">
								<button class="btn btn-outline btn-primary btn-lg" id="queryBtn" style="margin-left: 20px" type="button">
									<i class="fa fa-search"></i>&nbsp;查询
								</button>
								<button class="btn btn-outline btn-default btn-lg" id="queryBtn" style="margin-left: 20px" type="reset">
									<i class="fa fa fa-recycle"></i> &nbsp;清空
								</button>
							</div>
						</form>
					</div>
				</div>
				<div class="ibox-content forum-container">
					<div id="toolbar" class="btn-group">
						<shiro:hasPermission name="dict_add">
							<button class="btn btn-outline btn-primary" id="addBtn" style="margin-left: 20px" type="button">
								<i class="fa fa-plus"></i>&nbsp;新增
							</button>
						</shiro:hasPermission>
					</div>
					<table id="queryTable"></table>

				</div>
			</div>
		</div>

		<script src="${ctx}/static/js/plugins/jsTree/jstree.min.js"></script>
		<script type="text/javascript">
			$("#treeSearch").submit(function(e) {
				$("#dictTree").jstree(true).search($("#searchLable").val());
				return false;
			});

			function queryTable() {

				if ($("#parentId").val() == '') {
					sighMsg("请选择左侧字典类型节点");
					return false;
				}
				$("#queryTable").bootstrapTable('refresh');
			}

			$(function() {
				var oTable = new TableInit();
				oTable.Init();
				$("#queryBtn").click(function() {
					queryTable();

				});
				$('#dictTree').jstree({
					'core' : {
						'themes' : {
							"dots" : true
						},
						'data' : {
							"url" : "${ctx}/dict/treeList",
							"dataType" : "json"
						},
					},
					"plugins" : [ "search" ],
					"themes" : {
						"theme" : "default",

					}
				}).bind('dblclick.jstree', function(event, data) {
					$("#parentId").val('');
					var ref = $('#dictTree').jstree(true), sel = ref.get_selected();
					$("#parentId").val(sel[0]);
					queryTable();
				});

				$("#addBtn").click(function() {
					if ($("#parentId").val() == '' || $("#parentId").val() == "-1") {
						sighMsg("请选择字典类型节点");
						return false;
					}
					openWindows('新增', "${ctx}/dict/addPage?parentId=" + $("#parentId").val(), '600px');
				});

			});
			var TableInit = function() {
				var oTableInit = new Object();
				//初始化Table
				oTableInit.Init = function() {
					var config = bootstrapTableConfig();
					config.url = '${ctx}/dict/list';
							config.queryParams = oTableInit.queryParams,// 传递参数（*）
							config.columns = [
									//	{checkbox : false},
									{
										//field: 'Number',//可不加  
										title : '序号',//标题  可不加  
										formatter : function(value, row, index) {
											return index + 1;
										}
									},
									{
										field : 'id',
										title : '操作',
										formatter : function(value, row, index) {
											return '<shiro:hasPermission name="dict_view"> <button class="btn btn-default btn-circle" type="button" data-toggle="tooltip" data-placement="bottom" title="查看详情" onclick="detail(\''
													+ value
													+ '\')"><i class="fa fa-ellipsis-h"></i></button> </shiro:hasPermission>'
													+ '&nbsp;'
													+ '<shiro:hasPermission name="dict_update"> <button class="btn btn-warning btn-circle" type="button" data-toggle="tooltip" data-placement="bottom" title="修改" onclick="edit(\''
													+ value
													+ '\')"><i class="fa fa-edit"></i></button> </shiro:hasPermission>'
													+ '&nbsp;'
													+ '<shiro:hasPermission name="dict_delete"><button class="btn btn-danger btn-circle" type="button" data-toggle="tooltip" data-placement="bottom" title="删除" onclick="deleteInfo(\''
													+ value + '\')"><i class="fa fa-remove"></i></button></shiro:hasPermission>';
										}
									}, {
										field : 'typeCode',
										title : '类型编码'
									}, {
										field : 'typeName',
										title : '类型名称'
									}, {
										field : 'parentName',
										title : '上级类型名称'
									}, {
										field : 'typeValue',
										title : '数据值'
									}, {
										field : 'sort',
										title : '排序'
									}, {
										field : 'updateByUserName',
										title : '操作人'
									}, {
										field : 'statusName',
										title : '状态'
									}, {
										field : 'updateDate',
										title : '更新时间'
									} ];
					$('#queryTable').bootstrapTable(config);
				};
				//得到查询的参数
				oTableInit.queryParams = function(params) {
					var form = formToJson("queryForm");
					form.limit = params.limit;
					form.offset = params.offset;
					form.parentId = $("#parentId").val();
					return form;
				};
				return oTableInit;
			};
			function detail(id) {
				openWindows('查看', "${ctx}/dict/viewPage?id=" + id);
			}
			function edit(id) {
				openWindows('修改', "${ctx}/dict/editPage?id=" + id, "600px");
			}
			function deleteInfo(id) {
				layer.confirm('您确定要删除该条记录吗?', {
					icon : 3,
					title : '提示'
				}, function(index) {
					$.post(basePath + "/dict/delete", {
						id : id
					}, function(data) {
						if (data.success) {
							succuceMsg(data.msg);
							if ($("#parentId").val() == parentId) {
								parent.$('#dictTree').jstree(true).refresh();
							}
							queryTable();
							parent.layer.close(index);
						} else {
							errorMsg(data.msg);
						}
					}, "json");
					layer.close(index);
				});
			}
		</script>
</body>
</html>